package com.xzk.ExpressInnWeb.web.filter;

import com.xzk.ExpressInnWeb.bean.Courier;
import com.xzk.ExpressInnWeb.service.CourierService;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter({"/addExpress.html","/expressAssist.html",
        "/infoExpress.html","/pickExpress.html",
        "/wechat/findExpressesByStaffPhone.do","/wechat/updateStatus.do",
        "/wechat/getExByCode.do","/wechat/insertEx.do"})
public class WechatAdminFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        Object identity = req.getSession().getAttribute("identity");
        if (identity==null){
            resp.sendRedirect("/login.html");
        } else {
            String identityStr = (String) identity;
            if ("courier".equals(identityStr)){
                chain.doFilter(request,response);
            } else {
                resp.sendRedirect("/index.html");
            }
        }
    }

    @Override
    public void destroy() {

    }
}
